package com.haoshuang.zhouzhoubang.ui.page.home.settings.skill.record

import android.content.Context
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.haoshuang.zhouzhoubang.R
import com.haoshuang.zhouzhoubang.databinding.ActivitySkillRecordBinding
import com.haoshuang.zhouzhoubang.model.bean.Jn2Bean
import com.mufeng.libs.base.BaseVMActivity
import com.mufeng.libs.core.finishAll
import com.mufeng.libs.core.setEmptyData
import com.mufeng.libs.state.observeState
import com.mufeng.libs.utils.view.click
import com.mufeng.libs.utils.startPage
import com.mufeng.libs.utils.toast

/**
 *  技能记录
 */
class SkillRecordActivity : BaseVMActivity<SkillRecordViewModel, ActivitySkillRecordBinding>() {

    companion object {
        fun launch(context: Context){
            context.startPage<SkillRecordActivity>()
        }
    }

    var list= arrayListOf<Jn2Bean>()
    lateinit var adapter: JnAdapter

    override fun initView(savedInstanceState: Bundle?) {
        binding.titleBar.title = "技能记录"
        binding.titleBar.leftImageView().click { finish() }

        adapter= JnAdapter(list)
        binding.recyclerView.layoutManager = LinearLayoutManager(this)
        binding.recyclerView.adapter=adapter
        adapter.setEmptyData()
        vm.getTeamCategoryList()
        binding.refreshLayout.setOnRefreshListener {
            isShowing = false
            vm.getTeamCategoryList()
        }
    }

    override fun initData() {
    }

    override fun startObserve() {
        vm.getTeamCategoryListData.observeState(this){
            onLoading { showLoading() }
            onError { code, msg ->
                dismissLoading()
                binding.refreshLayout.finishAll()
                toast(msg)
                list.clear()
                adapter.notifyDataSetChanged()
                adapter.isStateViewEnable = true
            }
            onSuccess {
                dismissLoading()
                binding.refreshLayout.finishAll()
                list.clear()
                list.addAll(it?.data?:emptyList())
                adapter.notifyDataSetChanged()
                adapter.isStateViewEnable = true
            }
        }
    }

}